<template>
  <div >
     
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
      size="mini"
      type="primary"
            icon="el-icon-plus"
          @click="handleAdd"
          v-hasPermi="['cmdb:savefile:post']"
        >新增状态
        </el-button>
      </el-col>

    </el-row>

    <el-table v-loading="loading" :data="statusList" >
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="编号" width="50" align="center" type="index"/>
      <el-table-column label="状态"  width="100" align="center" prop="status" />
      <el-table-column label="描述"  align="center" prop="desc" :show-overflow-tooltip="true"/>
      <el-table-column label="创建日期" width="200" align="center" prop="create_time"/>
      <el-table-column label="操作人员" width="90" align="center" prop="user"/>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="150"
        v-if="hasPermi(['cmdb:clearsavefile:download:post'])"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="one_edit(scope.row)"
            v-hasPermi="['cmdb:clearsavefile:download:post']"
          >编辑
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['cmdb:savefile:{id}:delete']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>


    <!-- 对话框 -->
        <el-dialog
      :title="title"
      width="550px"
      :visible.sync="is_visible"
      :close-on-click-modal="false"
      :append-to-body="true"
    >
          <el-form
        :model="dataform"
        label-width="80px"
        :rules="rules"
        label-position="left"
      >
        <el-form-item
          label="状态"
          prop="status"
        >
                <el-input
        type="text"
        placeholder="请输入内容"
        v-model="dataform.status"
        maxlength="50"
        show-word-limit
        >
        </el-input>
        </el-form-item>
                <el-form-item
          label="描述"
          prop="desc"
        >
            <el-input
            type="textarea"
            placeholder="请输入内容"
            v-model="dataform.desc"
            :rows="5"
            maxlength="200"
            show-word-limit
            size="small"
            >
            </el-input>
        </el-form-item>

      </el-form>

            <center>
      <el-form label-width="0px" style="margin-right: 30px align:center">
      <el-form-item>
        <el-button size="small" style="width: 20%" type="primary" @click="on_submit()">提交</el-button>
        <el-button size="small" style="width: 20%" type="info"  @click="on_close()" >取消</el-button>
      </el-form-item>
    </el-form>
    </center>
    </el-dialog>
  </div>
</template>

<script>
  import {listStatus, addStatus, updateStatus,delStatus} from "@/api/vadmin/cmdb/status";
  import FileUpload from "@/components/FileUpload/index";

  export default {
    name: "status",
    components: {FileUpload},
    data() {
      return {
        // 遮罩层
        loading: true,
        // 显示搜索条件
        showSearch: true,
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        pid:1,
        edit_or_update:0,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name: undefined,
          type: undefined,
        },
        // 总条数
        total: 0,
        // 数据列表
        statusList: [],
        is_visible:false,
        dataform:{},
                rules:{desc:{ required: true, message: '请输入问题描述', trigger: 'blur' },
               status:{ required: true, message: '请输入维修方案', trigger: 'blur' },        }
      }
    },
    created() {
      this.getList();
    },
    mounted() {
    },
    methods: {
      /** 查询列表 */
      getList() {
        this.loading = true;
        listStatus({pid:this.pid}).then(response => {
          this.statusList = response.results;
          this.total = response.count;
          this.loading = false;
        });
      },
      /** 上传按钮操作 */
      handleAdd(row) {
        this.edit_or_update=0
        this.dataform={}
        this.is_visible = true;
        this.title = "新增状态";
      },
      on_close(){
          this.is_visible=false;
      },
      on_submit(){
        // 0编辑，1修改
        if (this.edit_or_update==0){
        this.dataform["pid"]=this.pid
        addStatus(this.dataform).then(response=>{
            this.is_visible=false
            this.getList({pid:this.pid})
        })
        }else{
          updateStatus(this.dataform).then(response=>{
              this.is_visible=false
          })  
        }

      },
            one_edit(row){
                this.edit_or_update=1
                this.title="编辑状态"
                this.is_visible=true
        this.dataform=row
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        this.$confirm('是否确认删除状态为为"' + row.status + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return delStatus(row.id);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
      },

    }

  }
</script>

<style scoped>

</style>
